﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using eTMS.Commons;

namespace eTMS.Helps
{
    public partial class frmRegister : eTMS.Controls.BaseForm
    {
        public frmRegister()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            LisenceInfo lic = new LisenceInfo();
            lic.Email = txtEmail.Text;
            lic.Organization = txtToChuc.Text;
            lic.ProductCode = txtProductCode.Text;
            lic.RequestCode = txtRequestCode.Text;
            lic.ProductRegisterCode = txtRegisterCode.Text;
            lic.UserName = txtNguoiDangKy.Text;
            LisenceInfo.Save(lic, Commons.Constants.APP_REGISTER_FILE);
            if (LisenceInfo.CheckRegister(Commons.Constants.APP_REGISTER_FILE))
            {
                MessageBox.Show("Bạn đã đăng ký thành công!");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                try
                {
                    System.IO.File.Delete(Commons.Constants.APP_REGISTER_FILE);
                }
                catch { }
                MessageBox.Show("Mã đăng ký không đúng bạn hãy nhập lại!");
            }
          
        }

        private void frmRegister_Load(object sender, EventArgs e)
        {
            txtRequestCode.Text = LisenceInfo.GetRequestCode();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(txtRequestCode.Text, true);
        }
    }
}